<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    
	
	<title>_入库登记</title>
	<script type="text/javascript">
	
        $(function() {
		    $("#queryForm").validate(); 
		    $("#inputForm").validate(); //为inputForm注册validate函数
			$("#_fromDate").datepicker({ format : 'yyyy-mm-dd' });
			$("#_toDate").datepicker({ format : 'yyyy-mm-dd' });
       });
	  
        //重设表单
        function formReset(){
          $("input[type=reset]").trigger("click");
        }
        
       //删除入库单
       function deleteBill(billId){
          
          $.ajax({
			   type : 'post',
				url : '${ctx}/cusInstorageBill/ajaxDelete',
				data : {
					billId:billId
				},
				dataType : 'json',
				success : function(data) {
				   if(data==true){
				      $("#queryForm").submit();
				   }else{
				      alert("网络繁忙，请稍后重试...");
				   }	
				},
				error : function() {
					alert("网络繁忙，请稍后重试...");
				}
			}); 
          
       }

		//添加入库单	
 		function add(){
 		  $("#windowTitle").html("添加总仓入库单");
 		  $("input[type=reset]").trigger("click");
 		  $("#submit_btn").attr("disabled",null);
		  $("#customerCode").attr("disabled",false);
		  $("#inwarehouseCode").attr("disabled",false);
 		  $("#inputForm").attr("action",'${ctx}/cusInstorageBill/create');
 		}
 		
 		//修改入库单
 		function update(billId){
 		
 		   $("input[type=reset]").trigger("click");
 		   $("#inputForm").attr("action",'${ctx}/cusInstorageBill/update');
 		
 		   $.ajax({
			   type : 'post',
				url : '${ctx}/cusInstorageBill/ajaxGetBill',
				data : {
					billId:billId
				},
				dataType : 'json',
				success : function(data) {
				
				    $("#customerCode").val(data.customerCode);
					$("#inwarehouseCode").val(data.inwarehouseCode);
					$("#boxNum").val(data.boxNum);
					$("#skuNum").val(data.skuNum);
					$("#goodsNum").val(data.goodsNum);
					$("#remarks").val(data.remarks);
					$("#id").val(data.id);
					$("#aboutCode").val(data.aboutCode);
		             
					$("#customerCode").attr("disabled",true);
					$("#inwarehouseCode").attr("disabled",true);
					$("#windowTitle").html("修改总仓入库单　　　　　　　　　　　　　　入库单号：<font color=blue>"+data.instorageCode+"</font>");
				},
				error : function() {
					alert("网络繁忙，请稍后重试...");
				}
			 }); 
				
 		}
 		
 		//添加or修改
 		function mySubmit(){
 		   $("#submit_btn").attr("disabled",true);
 		   
 		   if( $("#inputForm").valid() ){
 		      
 		        var customerCode=$("#customerCode").val().trim();
 		        var inwarehouseCode=$("#inwarehouseCode").val().trim();
 		        var aboutCode=$("#aboutCode").val().trim();
 		        var boxNum=$("#boxNum").val().trim();
 		        var skuNum=$("#skuNum").val().trim();
 		        var goodsNum=$("#goodsNum").val().trim();
 		        var remarks=$("#remarks").val().trim();
 		        var id=$("#id").val().trim();
 		       
 		        $.ajax({
				   type : 'post',
					url : '${ctx}/cusInstorageBill/ajaxCreateOrUpdate',
					data : {
						customerCode:customerCode,
						inwarehouseCode:inwarehouseCode,
						aboutCode:aboutCode,
						boxNum:boxNum,
						skuNum:skuNum,
						goodsNum:goodsNum,
						remarks:remarks,
						id:id
					},
					dataType : 'json',
					success : function(data) {
					   if(data==true){
					     $("#_customerCode").val(customerCode);
					     $("#queryForm").submit();
					   }else{
					     alert("网络繁忙，请稍后重试...");
					   }
					   $("#submit_btn").attr("disabled",false);
					},
					error : function() {
						alert("网络繁忙，请稍后重试...");
						$("#submit_btn").attr("disabled",false);
					}
				 }); 
 		      
 		   }else{
 		      $("#submit_btn").attr("disabled",false);
 		   }
 		}
 		
		
	  
    </script>
</head>

<body>
    <c:if test="${not empty message}">
		<div id="message" class="alert alert-success"><button data-dismiss="alert" class="close">×</button>${message}</div>
	</c:if>
	
	<div>
	   <a   href="#detail" role="button" data-toggle="modal" id="${timeliness.orderNo}" class="btn btn-primary" onclick="add();" >登记入库单</a>
	</div>
	<div style="height: 10px;"></div>
	
	<div class="row">
		<div class="span12" style="margin-left: 20px;">
			<form class="form-search" id="queryForm" action="${ctx}/cusInstorageBill/queryCusInstorageBill" method="post">
			
			    <label style="margin-left: 10px;">商家</label>
				 <select  name="_customerCode"  id="_customerCode" value="${param._customerCode}"  class="input-medium required" onchange="ajaxAreaGroup(this,'_warehouseCode');">
					<option value=""></option>
					<c:forEach items="${customerList}" var="customer">
						<option value="${customer.customerCode}"
						<c:if test="${customerCode eq customer.customerCode}">selected=selected</c:if>
						>${customer.customerName}</option>
					</c:forEach>
				</select>
			
				<label style="margin-left: 10px;">入库仓库</label>
				   <select  name="_warehouseCode"  id="_warehouseCode" value="${param._warehouseCode}"  class="input-medium" >
				     <option value=""></option>  
				     <c:forEach items="${warehouseList}" var="warehouse">
				       <option value="${warehouse.groupCode}" 
				       <c:if test="${warehouseCode eq warehouse.groupCode }">selected=selected</c:if>
				       >${warehouse.groupName}</option>
				     </c:forEach>
				</select>
				
				<label style="margin-left:10px;">入库单状态：</label> 
				<select  name="_status"  id="_status" value="${param._status}"  class="input-medium">
					<option value="" <c:if test="${param._status eq ''}">selected=selected</c:if> ></option>
				    <option value="1" <c:if test="${param._status eq '1'}">selected=selected</c:if> >已登记</option>
				    <option value="2" <c:if test="${param._status eq '2'}">selected=selected</c:if> >已点收</option>
				    <option value="3" <c:if test="${param._status eq '3'}">selected=selected</c:if> >审核通过</option>
				    <option value="4" <c:if test="${param._status eq '4'}">selected=selected</c:if> >审核驳回</option>
				    <option value="5" <c:if test="${param._status eq '5'}">selected=selected</c:if> >任务执行中</option>
				    <option value="6" <c:if test="${param._status eq '6'}">selected=selected</c:if> >完成所有任务</option>
				</select>
				
				<label>&nbsp;&nbsp;&nbsp;入库日期&nbsp;&nbsp;&nbsp;从：</label> 
			 	<input type="text" name="_fromDate" id="_fromDate"  class="input-medium" value="${param._fromDate}" style="margin-left: -10px;"> 
			 	<label>至：</label> 
			 	<input type="text" name="_toDate" id="_toDate" class="input-medium" value="${param._toDate}" style="margin-left: -10px;"> 
			 	
			    <button type="submit" class="btn" style="margin-left: 10px;">搜索</button>
		    </form>
	    </div>
	</div>
	
	<table id="contentTable" class="table table-striped table-bordered table-condensed">
		<thead><tr>
		    <th style="width: 100px;">商家名称</th>
		    <th style="width: 80px;">入库类型</th>
		    <th style="width: 80px;">出货仓库</th>
		    <th style="width: 80px;">相关单号</th>
		    <th style="width: 80px;">入库网点</th>
		    <th style="width: 180px;">入库单号</th>
			<th style="width: 80px;">箱子数量</th>
			<th style="width: 80px;">SKU数量</th>
			<th style="width: 80px;">商品数量</th>
			<th style="width: 150px;">入库时间</th>
			<th style="width: 80px;">当前状态</th>
			<th style="width: 100px;">创建人</th>
			<th style="width: 150px;">管理</th>
		</tr></thead>
		<tbody>
		
		<c:if test="${empty billList or billList.size() eq 0}">
	       <tr><td colspan="19" height="50" style="vertical-align:middle; text-align: center;color: gray;font-size: 20px;">无数据</td></tr>
	    </c:if>
	    
		<c:if test="${not empty billList}">
				<c:forEach items="${billList}" var="bill">
					<tr>
						<td>${bill.customer.customerName}</td>
						<td>
						  <c:if test="${bill.billType eq '1' }">总仓入库</c:if> 
						  <c:if test="${bill.billType eq '2' }">调拨入库</c:if>
						</td>
						<td>${bill.customer.customerName}</td>
						<td>${bill.aboutCode}</td>
						<td>${bill.inwarehouse.groupName}</td>
						<td>${bill.instorageCode}</td>
						<td>${bill.boxNum}</td>
						<td>${bill.skuNum}</td>
						<td>${bill.goodsNum}</td>
						<td>${fn:substring(bill.inTime,0,19)}</td>
						<td><c:if test="${bill.status eq '1' }">已登记</c:if> <c:if
								test="${bill.status eq '2' }">已点收</c:if> <c:if
								test="${bill.status eq '3' }">审核通过</c:if> <c:if
								test="${bill.status eq '4' }">审核不通过</c:if> <c:if
								test="${bill.status eq '5' }">任务执行中</c:if> <c:if
								test="${bill.status eq '6' }">上架完成</c:if>
						</td>
						<td>${bill.creater.realname}</td>
						<td>
						   
						    <c:if test="${bill.status eq '1' or bill.status eq '2'}">
						        <button type="button" class="btn btn-danger" onclick="deleteBill('${bill.id}')">删除</button>
							</c:if> 
							
							<c:if test="${bill.status ne '1' and bill.status ne '2'}">
								<input type="button" class="btn" disabled="disabled" value="删除" />
							</c:if>

							<a href="#detail" data-toggle="modal" class="btn btn-primary" onclick="update('${bill.id}');">修改</a>
						</td>
					</tr>
				</c:forEach>
			</c:if>
			
		</tbody>
	</table>
	
	<!-- 添加/修改入库单 -------------------------------------------------------------------------------------------------->
	<div style="display: none; width:900px;" class="modal hide fade"  id="detail" >
	<form id="inputForm"  method="post" class="form-horizontal">
	
		<!-- 头 -->
		<div class="modal-header" style="height: 20px; vertical-align: middle; " >
		<span style="font-size: large; font-weight: bold;" id="windowTitle"></span>
		</div>
		<!-- 体 -->
		<div class="modal-body" style="height: 250px;">
						<fieldset>
						      <input type="hidden" id="id" name="id"/>
						      
							  <!-- 行1 -->
						      <div class="row" >
						      
				                   <div class="span4" style="margin-left: -80px;">
											<div class="control-group">
												<label  class="control-label">商家名称:</label>
												<div class="controls">
													 <select  name="customerCode"  id="customerCode"  class="required" onchange="ajaxAreaGroup_1(this,'inwarehouseCode');" style="margin-left: -10px; width: 200px;">
														<option value=""></option>
														<c:forEach items="${customerList}" var="customer">
														<option value="${customer.customerCode}"
														<c:if test="${customerCode eq customer.customerCode}">selected=selected</c:if>
														>${customer.customerName}</option>
														</c:forEach>
													</select>
												</div>
											</div>
							          </div>
				       
							        
							           <div class="span4">
											<div class="control-group">
											
												<label  class="control-label" style="margin-left:-10px;">入库仓库:</label>
												<div class="controls">
													<select id="inwarehouseCode" name="inwarehouseCode" class="required"   style="margin-left: -20px; width: 200px;" >
														<option value=""></option>
														<c:forEach items="${warehouseList}" var="wm">
															<option value="${wm.groupCode}">${wm.groupName}</option>
														</c:forEach>
													</select>
												</div>
											</div>
							          </div>
							          
							          <div class="span4">
								      	   <div class="control-group">
												<label  class="control-label" style="margin-left:-20px;">相关单号:</label>
												<div class="controls">
												    <input type="text" id="aboutCode" name="aboutCode"   style="margin-left: -30px; width: 188px;">
												</div>
											</div>
								         </div>
							          
						       </div>
						       
						       
						        <!-- 行2 -->
							   <div class="row" >
							   			<div class="span4" style="margin-left: -80px;">
									      	    <div class="control-group">
													<label  class="control-label">箱子数量:</label>
													<div class="controls">
													   <input type="text" id="boxNum" name="boxNum"  class="digits" style="margin-left: -10px; width: 188px;">
													</div>
											   </div>
								         </div>
								         <div class="span4">
								      	    <div class="control-group">
												<label  class="control-label" style="margin-left:-10px;">SKU数量:</label>
												<div class="controls">
													 <input type="text" id="skuNum" name="skuNum"  class="digits" style="margin-left: -20px; width: 188px;">
												</div>
											</div>
								      	 </div>
								      	 <div class="span4">
								      	   <div class="control-group">
												<label  class="control-label" style="margin-left:-20px;">商品数量:</label>
												<div class="controls">
												    <input type="text" id="goodsNum" name="goodsNum"  class="digits" style="margin-left: -30px; width: 188px;">
												</div>
											</div>
								         </div>
							       </div>   
							       
						      <!-- 行3 -->
						      <div class="row" >

									 <div class="span12" style="margin-left: -80px;">
							      	    <div class="control-group">
											<label  class="control-label" style="margin-left:0px;">备注信息:</label>
											<div class="controls">
												<textarea rows="4" id="remarks" name="remarks" style="width: 760px; height:100px; margin-left: -10px;" maxlength="100"></textarea>
											</div>
										</div>
						              </div>
							      	  
						     </div> 
						     
							
							
							</fieldset>	      
		      
		</div>
		<!-- 尾 -->
		<div class="modal-footer">
			<input id="submit_btn" class="btn btn-primary"  type="button" value="提交" onclick="mySubmit();"/>&nbsp;	
			<input id="cancel_btn" class="btn" type="button" data-dismiss="modal" value="返回" />
			<input type="reset" style="display:none;" /> 
		</div>
		
        </form> 
     </div>
     <!------------------------------------------------------------------------------------------------------------->
	
</body>
</html>
